﻿Public Class CronogramaPresentacionDAO
    Public Shared Function insertarCronogramaPresentacion(ByVal MesId As Integer, ByVal CronogramaPresentacionAno As Integer, ByVal CronogramaPresentacionObservaciones As String) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            Constante.esNulo(CronogramaPresentacionObservaciones)
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_CronogramaPresentacion"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.INSERTAR).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionFechaCreacion", Date.Now).DbType = DbType.DateTime
                    .AddWithValue("@MesId", MesId).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionAno", CronogramaPresentacionAno).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionObservaciones", CronogramaPresentacionObservaciones).DbType = DbType.String
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function obtenerCronogramasPresentaciones(ByVal CronogramaPresentacionId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_CronogramaPresentacion_obtener", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@CronogramaPresentacionId", CronogramaPresentacionId).DbType = DbType.Int32
            da.Fill(ds, "CronogramasPresentaciones")

            Return ds.Tables("CronogramasPresentaciones")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function actualizarCronogramaPresentacion(ByVal CronogramaPresentacionId As Integer, ByVal MesId As Integer, ByVal CronogramaPresentacionAno As Integer, ByVal CronogramaPresentacionObservaciones As String, ByVal FechaCreacion As Date) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            Constante.esNulo(CronogramaPresentacionObservaciones)
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_CronogramaPresentacion"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ACTUALIZAR).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionId", CronogramaPresentacionId).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionFechaCreacion", FechaCreacion).DbType = DbType.DateTime
                    .AddWithValue("@MesId", MesId).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionAno", CronogramaPresentacionAno).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionObservaciones", CronogramaPresentacionObservaciones).DbType = DbType.String
                End With
                .Connection = cn
                .ExecuteNonQuery()

            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function eliminarCronogramaPresentacion(ByVal CronogramaPresentacionId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_CronogramaPresentacion"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ELIMINAR).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionId", CronogramaPresentacionId).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionFechaCreacion", Constante.FECHAVACIA).DbType = DbType.DateTime
                    .AddWithValue("@MesId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionAno", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@CronogramaPresentacionObservaciones", Constante.VACIO).DbType = DbType.String
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With

            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function idCronogramaPresentacion(ByVal CronogramaPresentacionAno As Integer, ByVal MesId As Integer) As Integer
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim cmd As New SqlClient.SqlCommand("usp_CronogramaPresentacion_id", cn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@CronogramaPresentacionAno", CronogramaPresentacionAno).DbType = DbType.Int32
            cmd.Parameters.AddWithValue("@MesId", MesId).DbType = DbType.Int32
            Dim id As Integer
            id = cmd.ExecuteScalar
            Return id
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function comboCronogramaPresentacion() As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_CronogramaPresentacion_combo", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.Fill(ds, "CronogramasPresentaciones")

            Return ds.Tables("CronogramasPresentaciones")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function comboCronogramaPresentacionDs() As DataSet
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_CronogramaPresentacion_combo", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.Fill(ds, "CronogramasPresentaciones")

            Return ds
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function crearReportePresentacion(ByVal CronogramaPresentacionId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_ReporteCronogramaPresentacion", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@CronogramaPresentacionId", CronogramaPresentacionId).DbType = DbType.Int32
            da.Fill(ds, "CronogramaPresentacion")
            Return ds.Tables("CronogramaPresentacion")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function buscarCronogramasPresentacion(ByVal CronogramaPresentacionAño As Integer, ByVal MesId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_cronogramaPresentacion_buscar", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@CronogramaPresentacionAño", CronogramaPresentacionAño).DbType = DbType.Int32
            da.SelectCommand.Parameters.AddWithValue("@MesId", MesId).DbType = DbType.Int32
            da.Fill(ds, "CronogramasPresentacion")

            Return ds.Tables("CronogramasPresentacion")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function vistaCronogramasPresentaciones(ByVal CronogramaPresentacionId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_CronogramaPresentacion_vista", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@CronogramaPresentacionId", CronogramaPresentacionId).DbType = DbType.Int32
            da.Fill(ds, "CronogramasPresentaciones")

            Return ds.Tables("CronogramasPresentaciones")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function filtroCronogramaPresentacion(ByVal CronogramaPresentacionAno As Integer, ByVal MesId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_CronogramaPresentacion_filtro", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@CronogramaPresentacionAno", CronogramaPresentacionAno).DbType = DbType.Int32
            da.SelectCommand.Parameters.AddWithValue("@MesId", MesId).DbType = DbType.Int32
            da.Fill(ds, "CronogramasPresentaciones")

            Return ds.Tables("CronogramasPresentaciones")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

End Class
